import  cv2
# 黑帽 = 原图 -闭运算
img = cv2.imread(' ./1.jpg')
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
img1 = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)
cv2.imshow('img',img)
cv2.imshow('img1',img1)
cv2.waitKey(0)